import java.util.LinkedList;

public class Candidates extends LinkedList<Candidate> {   
    
	/**
     * 1 = Ace, 2 = King, 3 = Queen, 4 = Jack
     */
    public Candidates(){
        super.add(new Candidate(1, 2));
        super.add(new Candidate(2, 2));
        super.add(new Candidate(3, 2));
        super.add(new Candidate(4, 2));
    }
    
    /**
     * Removes a Candidate to the LinkedList. If there are no more candidates available, 
     * remove it from the list.
     */
    public Candidate remove(int index){
        Candidate candidate = get(index);
        candidate.takeOne();
        
        if(candidate.getAvailable() == 0){
        	candidate = super.remove(index);
        }
        
        return candidate;
    }
    
    /**
     * Adds a Candidate to the LinkedList. If the availability counts 1, add the new candidate
     * to the list.
     */
    public void add(int index, Candidate candidate){
        candidate.addOne();
        
        if(candidate.getAvailable() == 1){
        	super.add(index, candidate);
        }
    }
}